package dao;/*
@Date:2025/3/20
*/

import javabean.House;
import tool.MyhandleDbReflection;

import java.sql.SQLException;
import java.util.List;

public class Dao {

//列表
    public static List<House> find(){
        final List<House> list = MyhandleDbReflection.findList("select * from tb_house ", House.class);
        return list;
    }
    //新增
    public static int in(House hous){
        final int update = MyhandleDbReflection.update("insert into tb_house values(?,?,?,?,?,?)",hous.getId(),
                hous.getName(),hous.getTel(),hous.getAddress(),hous.getMoney(),hous.getState());
        return update;
    }
//更新
    public static int Update(House hous){
        final int update = MyhandleDbReflection.update(
                "UPDATE tb_house " +
                        "SET name= ?,tel=?, address = ?, money = ?, state = ? " +
                        "WHERE id = ?",
                //"update tb_house set  name= ?,tel=?, address = ?, money = ?, state = ?, where id = ?",
                hous.getName(),hous.getTel(),hous.getAddress(),hous.getMoney(),hous.getState(),hous.getId());
        return update;
    }

    //查找
    public static List<House> findone(int x) {
        String sql="select * from tb_house WHERE id ='"+x+"'";
        final List<House> list = MyhandleDbReflection.findList(
                sql,House.class
               // "select * from tb_house WHERE id ='"+hous.getId()+"'",javabean.House.class
                );
        return list;
    }
    //删除
    public static int del(int x){
        final int update = MyhandleDbReflection.update(
                "delete from tb_house WHERE id = ?",x);
                //"update tb_house set  name= ?,tel=?, address = ?, money = ?, state = ?, where id = ?",

        return update;
    }
    //登录
    public static boolean login() throws SQLException {
        final boolean flag = MyhandleDbReflection.isAdmin();
        return flag;
    }
    //验证码
    public static String generateCode() {
        final String cap = MyhandleDbReflection.getCap();
        return cap;
    }
}
